package com.zhekou.web.action.admin;

import com.zhekou.bo.Product;
import com.zhekou.service.ProductService;
import com.zhekou.util.JdbcPage;
import com.zhekou.web.action.BaseAction;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.integration.spring.SpringBean;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by IntelliJ IDEA.
 * User: unicorn3964
 * DateTime: 12-11-23 下午1:43
 */
@UrlBinding("/admin.do")
public class AdminAction extends BaseAction {
    private static final Logger logger = LoggerFactory.getLogger(AdminAction.class);
    @SpringBean
    private ProductService productService;
    private JdbcPage<Product> page;
    private String username;
    private String password;

    @DefaultHandler
    public Resolution loginPre() {
        return getAdminResolution("login");
    }

    public Resolution login() {
        if (StringUtils.equals(username, "admin") && StringUtils.equals(password, "admin")) {
            page = productService.getList(curPage, pageSize);
            return getAdminResolution("main");
        } else {
            return getAdminResolution("login");
        }
    }

    public Resolution verify() {
        page = productService.getList(curPage, pageSize);
        return getAdminResolution("main");
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setProductService(ProductService productService) {
        this.productService = productService;
    }

    public JdbcPage<Product> getPage() {
        return page;
    }

    public void setPage(JdbcPage<Product> page) {
        this.page = page;
    }
}
